package Backwards;

import java.util.Collection;

import javax.ejb.EJBObject;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import Helpers.ApplicationLogger;

public class EJBBackward {

	public class BeanController
	{
		Collection<EJBObject> GetBean()
		{
			return null;
		}
		
		public Object GetBeanByJNDILookup(String lookupString)
		{
			InitialContext ctx = null;
			try {
				ctx = new InitialContext();
			} catch (NamingException e) {
				ApplicationLogger.getInstance().LOG.error(e.getMessage());
			}
			
			Object bean = null;
			try {
				ApplicationLogger.getInstance().LOG.info("Trying to load bean");
				bean = ctx.lookup(lookupString);
				ApplicationLogger.getInstance().LOG.info("Bean loaded");
				if(bean != null)
				{
					ApplicationLogger.getInstance().LOG.info("Bean has founded");
				}
				else
				{
					ApplicationLogger.getInstance().LOG.info("Bean is null");
				}
			} catch (NamingException e) {
				ApplicationLogger.getInstance().LOG.error("ERROR: " + e.getMessage());
			}
			
			return bean;
		}
	}
}
